# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=quarter
pkgbase=mingw-w64-${_realname}-hg
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-hg"
pkgver=r507+.4040ac7a14cf+
pkgrel=1
pkgdesc="Light-weight glue library that provides seamless integration between Coin and Qt5 (mingw-w64)"
arch=('any')
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-qt5"
         "${MINGW_PACKAGE_PREFIX}-coin3d")
makedepends=("mercurial" "${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-gcc")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
url='https://bitbucket.org/Coin3D/simage/overview'
source=("${_realname}"::"hg+https://bitbucket.org/Coin3D/Quarter"
        001-add-pkg-config.patch
        002-install-folders.patch)
options=(!strip staticlibs)
sha256sums=('SKIP'
            'c527a789c263cb6fc7dad59e9ebf6682c5fa0f4a6bf2daa05b327e3b278b92a1'
            'b324f0169d344471a4befc849d96e125d77ce8fb57e98826fa42b3c08f384030')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(hg identify -n)" "$(hg identify -i)"
}

prepare() {
  cd ${srcdir}/${_realname}
  patch -p1 -i ${srcdir}/001-add-pkg-config.patch
  patch -p1 -i ${srcdir}/002-install-folders.patch
}

build() {
  local -a extra_config
  if check_option "debug" "y"; then
    extra_config+=( -DCMAKE_BUILD_TYPE=Debug )
  else
    extra_config+=( -DCMAKE_BUILD_TYPE=Release )
  fi

  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DQuarter_BUILD_STATIC_LIBRARY=OFF \
    -DQuarter_BUILD_PLUGIN=ON \
    -DQuarter_BUILD_EXAMPLES=ON \
    -DUSE_SIM_FIND=OFF \
    ${extra_config} \
    ../${_realname}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
